package cn.tedu.csmall.passport.config;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;

/**
 * 描述： Validation配置类
 *
 * @author tangxuesong
 * @date Created in 2022/11/1 14:27
 */
@Slf4j
@Configuration
public class ValidationConfiguration {

    public ValidationConfiguration(){
        log.info("创建配置类对象：ValidationConfiguration");
    }

    @Bean
    public Validator validator(){
        return Validation.byProvider(HibernateValidator.class)
                // 开始配置
                .configure()
                // 快速失败，即检查请求参数时，一旦发现某个参数不符合规则，则视为失败，并停止检查（剩余未检查的部分将不会被检查）
                .failFast(true)
                .buildValidatorFactory()
                .getValidator();
    }
}
